import type { Context } from 'koa';
import { UserService } from '@/services/user';
import { ResponseErrors } from '@/enums/responseErrors';
import { QueryUsersDto } from '@/dtos/queryUsers.dto';

/**
 * 获取用户列表
*/
export const queryUsersController = async (ctx: Context) => {
  const input = ctx.request.body;
  const params = await ctx.vailParams<QueryUsersDto>(QueryUsersDto, input);

  const page = params.page || 1;
  const pageSize = params.pageSize || 10;

  const result = await UserService.queryUsersByPage({
    page,
    pageSize,
    sorter: params.sorter,
    filters: params.filters
  });

  ctx.sendSuccess({
    page,
    pageSize,
    ...result
  })
}
